<?php
namespace app\admin\controller;

class Orderclient extends Admin{
    public function __construct(){
        parent::__construct();
        $this->model = 'OrderClient';
        $this->assign("model",$this->model);
    }
    public function index_stat(){
    	
    	return $this->fetch();
    }

    public function get_where_map(){
        $status = input('param.status/s');
        $kind = input('param.kind/s');
        $startdate = input('param.startdate/s');
        $enddate = input('param.enddate/s');
        $dealerid = input('param.dealerid/d');
        $keywords = input('param.keywords/s');
        $whereDatas = [];
        if (!is_null($status) && $status != '') {
            $whereDatas['status'] = $status;
        }
        if (!is_null($kind) && $kind) {
            $whereDatas['kind'] = $kind;
        }
        if ($dealerid) {
            $whereDatas['dealerid'] = $dealerid;
        }else{
            if ($this->uinfo['roleid'] == 4) {
                $dealerids = model('AdminUser')->where('puserid', $this->uinfo['userid'])->where('roleid', 6)->column('userid');
                $whereDatas['dealerid'] = ['in', $dealerids];
            }elseif ($this->uinfo['roleid'] == 6) {
                $whereDatas['dealerid'] = $this->uinfo['userid'];
            }
        }
        $starttime = $startdate ? strtotime($startdate) : 0;
        $endtime = $enddate ? strtotime($enddate) : 0;
        if ($starttime && $endtime) {
            $whereDatas['addtime'] = ['between', [$starttime,$endtime]];
        }elseif ($starttime && !$endtime) {
            $whereDatas['addtime'] = ['egt', $starttime];
        }elseif ($endtime && !$starttime) {
            $whereDatas['addtime'] = ['elt', $endtime];
        }
        if ($keywords) {
            $whereDatas['content|huifu'] = ['like', "%$keywords%"];
        }
        trace($whereDatas);
        return $whereDatas;
    }
    public function index()
    {
        $where['status'] = 0;
        if ($this->uinfo['roleid'] == 1) {
            $where['roleid'] = 6;
        }elseif ($this->uinfo['roleid'] == 4) {
            $where['roleid'] = 6;
            $where['puserid'] = $this->uinfo['userid'];
        }elseif ($this->uinfo['roleid'] == 6) {
            $where['userid'] = $this->uinfo['userid'];
        }
        $deallist = model('AdminUser')->where($where)->order('userid desc')->column('userid, username');

        $this->assign('deallist', $deallist);
        return $this->fetch();
    }
}